/**
 * 
 * author：gaoxingliang@outlook.com
 * created:2015年8月15日 上午9:46:30  
 */
package org.gxl.learn;

import java.io.File;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

/**
 * 示例代码演示使用jxl写excel文件<br>
 * <b>jxl只支持excel2003 已经不推荐使用了<b>
 * <br>
 * 如下的数据：<br>
 * id	name<br>
user1	name1<br>
user2	name2<br>
user3	name3<br>
user8	name8<br>
user9	name9<br>
 * 
 * 
 * @author gxl
 *
 */
public class WriteExcelByJXL
{

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception
	{
		// TODO Auto-generated method stub
		File file = new File("test.xls");
		file.createNewFile();
		//创建工作簿
		WritableWorkbook workbook = Workbook.createWorkbook(file);
		//工作表
		WritableSheet sheet = workbook.createSheet("sheet1", 0);
		Label label = null;
		String [] title = new String[] {"id" , "name"};
		for (int i =0; i< title.length ; i++)
		{
			label = new Label(i, 0, title[i]);
			sheet.addCell(label);
		}
		for (int i = 1; i < 10; i ++)
		{
			/**
			 * Creates a cell which, when added to the sheet, will be presented at the specified 
			 * column and row co-ordinates and will contain the specified text 
			 * 第一个参数列 第二个参数行 第三个参数就是内容
			 */
			label = new Label(0, i, "user" + i);
			sheet.addCell(label);
			
			label = new Label(1,i, "name" + i);
			sheet.addCell(label);
		}
		//写入数据
		workbook.write();
		workbook.close();
	}

}
